﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Buccontrols;
using PluginInterface;
using System.Text.RegularExpressions;

namespace Buccaneer
{
    public partial class MenuControl : PluginControl
    {
        private MenuActivatePluginAction refreshAction;

        public MenuControl()
        {
            InitializeComponent();

            this.refreshAction = new MenuActivatePluginAction(this);
            MainProgram.Plugins.RegisterAction(refreshAction);
        }

        private void btn_refresh_Click(object sender, EventArgs e)
        {
            this.refreshAction.Execute(new string[] { tbx_pluginname.Text });
        }
    }

    public class MenuActivatePluginAction : PluginAction
    {
        PluginControl pc;

        public MenuActivatePluginAction(PluginControl pc)
        {
            this.pc = pc;
            base.name = "activatePlugin";
            base.func = new ActionFunction(this.MenuActivatePlugin);
            base.pars.Add("pluginFormName", "The form to activate");
        }

        public void MenuActivatePlugin(string[] args)
        {
            pc.SuspendLayout();
            int i = 0;
            try
            {
                pc.Controls.Clear();
                foreach (PluginAction p in MainProgram.selectedPlugin.Instance.MenuActions.Values)
                {
                    Button btn = new Button();
                    if (p.NotOnlyOptionalPars()) btn.Enabled = false;
                    btn.Text = p.friendlyName == null ? p.name : p.friendlyName;
                    btn.Name = p.name;
                    btn.Location = new Point(0, 25 * i);
                    btn.Size = new Size(pc.Width, 25);
                    btn.Parent = pc;
                    btn.Click += new EventHandler(btn_Click);
                    btn.MouseDown += new MouseEventHandler(pc.PluginForm_MouseDown);
                    pc.Controls.Add(btn);
                    i++;
                    btn = null;
                }
            }
            catch { }
            pc.Height = i * 25;
            pc.ResumeLayout(true);
        }

        public void btn_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act((sender as Button).Name, null);
        }
    }
}
